💡 AI 인사이트

🤖 AI가 여기에 결과를 출력합니다...

댓글 커뮤니티

쿠팡이벤트

이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

검색

    로딩 중이에요... 🐣

    [코담] 웹개발·실전 프로젝트·AI까지, 파이썬·장고의 모든것을 담아낸 강의와 개발 노트

    03 Pandas 실습 데이터 파이프라인 전체 흐름 | ✅ 저자: 이유정(박사)

    🧪 Pandas 실습: 데이터 파이프라인 전체 흐름 정리 (DL → DW → DM → Service DB)

    Python + Pandas + CSV 파일 기반으로 데이터 분석 파이프라인을 실습하는 예제입니다. 각 단계별 설명과 코드가 함께 정리되어 있습니다.


    ✅ 1단계: DL (Data Lake) – 원시 데이터 수집 및 저장

    import pandas as pd
    
    # 예시 원시 데이터
    raw_data = [
        {
            "가게명": "브런치카페 강남점",
            "주소": "서울 강남구 테헤란로 123",
            "리뷰": "진짜 맛있어요!",
            "별점": "⭐⭐⭐⭐",
            "카테고리": "카페, 양식",
            "전화번호": "+82-02-1234-5678",
            "운영시간": "09:00~21:00",
            "위도": "37.123456789012",
            "경도": "127.123456789012"
        }
    ]
    
    # 데이터프레임 생성 및 저장
    raw_df = pd.DataFrame(raw_data)
    raw_df.to_csv("raw_data/restaurant_raw.csv", index=False)
    raw_df.head()
    

    ✅ 2단계: DW (Data Warehouse) – 데이터 정제 및 구조화

    cleaned_data = []
    
    for row in raw_data:
        start_time, end_time = row["운영시간"].split("~")
        cleaned_data.append({
            "name": row["가게명"].split()[0],
            "branch_name": row["가게명"].split()[1],
            "address": row["주소"],
            "rating": row["별점"].count("⭐"),
            "category": row["카테고리"].split(",")[0].strip(),
            "cuisine_type": row["카테고리"].split(",")[1].strip(),
            "start_time": start_time,
            "end_time": end_time,
            "phone": row["전화번호"],
            "latitude": float(row["위도"]),
            "longitude": float(row["경도"]),
        })
    
    cleaned_df = pd.DataFrame(cleaned_data)
    cleaned_df.to_csv("csv_files/cleaned_restaurant_data.csv", index=False)
    cleaned_df.head()
    

    ✅ 3단계: DM (Data Mart) – 목적별 데이터 분리

    # 평점이 4 이상인 맛집 리스트
    high_rating_df = cleaned_df[cleaned_df["rating"] >= 4]
    high_rating_df.to_csv("dm/dm_top_rated_restaurants.csv", index=False)
    high_rating_df.head()
    

    ✅ 4단계: 서비스 DB 연동 시뮬레이션

    # 서비스 모델 저장용 데이터 확인
    print("🌟 Restaurant Model Fields")
    print(cleaned_df[["name", "branch_name", "address", "rating", "start_time", "end_time"]])
    

    ✅ 보너스: Pandas 주요 함수 실습

    # describe(): 요약 통계
    print(cleaned_df.describe())
    
    # value_counts(): 범주형 값 빈도수
    print(cleaned_df["category"].value_counts())
    
    # groupby(): 카테고리별 평균 평점
    print(cleaned_df.groupby("category")["rating"].mean())
    

    📌 요약: 데이터 흐름

    DL (Data Lake)

    • 다양한 원시 데이터를 수집하여 CSV/JSON으로 저장

    DW (Data Warehouse)

    • 정제된 표준 데이터셋 생성 (주소, 평점, 시간 등 정리)

    DM (Data Mart)

    • 목적별 데이터 추출 (추천 맛집 리스트 등)

    Service DB

    • Django 모델 기반 서비스에 연동되는 구조로 최종 저장

    Pandas 핵심 함수 실습

    • describe, value_counts, groupby 등 분석용 함수 실습
    TOP
    preload preload